package LABS.lab1;

/**************************************************************
* Class Lab1
* @author Jeff Thomas
* @vesion 1.0.0
* Date: 01.28.2008
* Copyright 2008, Jeff Thomas
***************************************************************/

import java.io.*;
import javax.swing.JOptionPane;

public class lab1 {
	public static void main(String[] args) throws IOException
	{
		//gather up all of the user input
		String name = inputName();
		int choice = inputLevel();
		String level = calcLevel(choice);
		int age = inputAge();
		output(name, level, age);
	}
/**************************************************************
* Input Name
* @return Name user entered into input box
* Task: 1. Get users name from input box
* Side Effects: None
***************************************************************/
	public static String inputName()
	{
		//input dialog for name
		String name = JOptionPane.showInputDialog(null, "Please enter your name", "Enter Name", JOptionPane.PLAIN_MESSAGE);
		return name;
	}
/**************************************************************
* Input Level
* @return - int value of level selected
* Tasks: 1. Show option dialog box with level choices
*			2. Prevent user from closing option dialog box and show
*				error if they do
* Side Effects: None
***************************************************************/
	public static int inputLevel()
	{
		//setup the array of grade level choices
		String[] levelChoices = {"Freshman", "Sophomore", "Junior", "Senior", "Graduate"};
		//options selection dialog for level
		int choice = JOptionPane.showOptionDialog(null, "Please select your level", "Level Selection", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, levelChoices, levelChoices[0]);
		//loop if we detect that the user closed the option box and display error
		while (choice == JOptionPane.CLOSED_OPTION)
		{
			JOptionPane.showMessageDialog(null, "You did not select a level!  Please select one.", "Error", JOptionPane.ERROR_MESSAGE);
			choice = JOptionPane.showOptionDialog(null, "Please select your level", "Level Selection", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, levelChoices, levelChoices[0]);
		}
		return choice;
	}	
/**************************************************************
* Input Age
* @return - Age of user
* Tasks: 1. Use BufferedReader for user to input age
* Side Effects: None
***************************************************************/
	public static int inputAge() throws IOException
	{		
		//bufferedreader for input of age
		BufferedReader inStream = new BufferedReader(new InputStreamReader(System.in));
		System.out.print("Enter age: ");
		int age = Integer.parseInt(inStream.readLine());
		return age;
	}
/**************************************************************
* Calculate Level
* @param choice - User selected value from inputLevel option box
* @return - String of user level
* Task: 1. Determine user level based from their selection
* Side Effects: None
***************************************************************/
	public static String calcLevel(int choice)
	{
		//declare the level string..
		String level = "";
		//switch case to determine string equivalent of level choosen
		switch(choice) 
		{
			case 0: level = "Freshman"; break;
			case 1: level = "Sophomore"; break;
			case 2: level = "Junior"; break;
			case 3: level = "Senior"; break;
			case 4: level = "Graduate"; break;
		}
		return level;
	}
/**************************************************************
* Output
* @param name - User's name
* @param level - User's level
* @param age - User's age
* Tasks: 1. Format string output
*			2. Display output in dialog box
***************************************************************/
	public static void output(String name, String level, int age)
	{
		String output = String.format("%3d years old %s is a %s", age, name, level);
		JOptionPane.showMessageDialog(null, output, "Result", JOptionPane.PLAIN_MESSAGE);
	}
}
/**************************************************************
* I, Jeff Thomas, certify that each part of this program was
* written by me, except as noted within the code.
*
*						_________________________
***************************************************************/